package com.shm.bytedance;

import java.util.*;

/**
 * @author: shm
 * @dateTime: 2020/10/11 10:26
 * @description: 追求极致II
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.nextLine();
        String[] ss = s.split(" ");
        int n = Integer.parseInt(ss[0]);
        int m = Integer.parseInt(ss[1]);
        int count = n;
        List<Integer[]> list = new ArrayList<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        while (count>0){
            String s1 = input.nextLine();
            String[] s1s = s1.split(" ");
            int x = Integer.parseInt(s1s[0]);
            int y = Integer.parseInt(s1s[1]);
            map.put(x,y+map.getOrDefault(x,0));
            count--;
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            list.add(new Integer[]{entry.getKey(),entry.getValue()});
        }
        Collections.sort(list, new Comparator<Integer[]>() {
            @Override
            public int compare(Integer[] o1, Integer[] o2) {
                if (o2[1].equals(o1[1])){
                    return o2[0]-o1[0];
                }else {
                    return o2[1] - o1[1];
                }
            }
        });

        StringBuffer str = new StringBuffer();
        for (int i = 0; i < m; i++) {
            str.append(list.get(i)[0]);
            if (i<m-1){
                str.append(" ");
            }
        }
        String str1 = str.toString();
        System.out.println(str1);
    }
}
